<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>嘉鱼县第一小学-全屏时钟</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .school-name {
            position: fixed;
            top: 10px;
            left: 15px;
            font-size: 1.2rem;
            color: inherit;
            z-index: 1000;
            transition: color 1s ease-in-out;
        }

        body {
            background-color: #000;
            color: #fff;
            font-family: Arial, sans-serif;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
            transition: background-color 1s ease-in-out, color 1s ease-in-out;
        }

        .container {
            text-align: center;
            margin-top: 15vh;
            width: 100%;
        }

        #clock {
            font-size: 20vw;
            font-weight: bold;
            margin: 20px 0;
            line-height: 1;
        }

        #date {
            font-size: 3vw;
            margin-bottom: 2vh;
        }

        #week, #timezone {
            font-size: 3vw;
            margin: 10px 0;
        }

        .controls {
            position: fixed;
            bottom: 20px;
            display: flex;
            flex-direction: column;
            gap: 15px;
            align-items: center;
        }

        button {
            padding: 12px 24px;
            font-size: 18px;
            background: #444;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: all 1s ease-in-out;
        }

        .color-options {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }

        .color-option {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            cursor: pointer;
            border: 2px solid #fff;
        }

        :fullscreen #clock {
            font-size: 25vw;
        }
    </style>
</head>
<body>
    <!-- 修复元素层级结构 -->
    <div class="school-name">嘉鱼县第一小学</div>
    
    <div class="container">
        <div id="date"></div>
        <div id="clock">--:--:--</div> <!-- 添加初始占位内容 -->
        <div id="week"></div>
        <div id="timezone">UTC +8</div>
    </div>

    <div class="controls">
        <div class="color-options">
            <div class="color-option" style="background: #00f" onclick="changeTheme('blue')"></div>
            <div class="color-option" style="background: #000" onclick="changeTheme('black')"></div>
            <div class="color-option" style="background: #fff" onclick="changeTheme('white')"></div>
        </div>
        <button onclick="toggleFullscreen()">显示全屏时钟</button>
    </div>

    <script>
        // 修复的时间更新函数
        function updateTime() {
            try {
                const now = new Date();
                
                // 时间显示
                const clock = document.getElementById('clock');
                clock.textContent = now.toLocaleTimeString('zh-CN', { 
                    hour12: false 
                });

                // 日期显示
                const date = document.getElementById('date');
                date.textContent = now.toLocaleDateString('zh-CN', { 
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit'
                }).replace(/\//g, '年').replace(/年/g, '月') + '日';

                // 星期显示
                const week = document.getElementById('week');
                week.textContent = now.toLocaleDateString('zh-CN', { 
                    weekday: 'long'
                });

                // 循环调用
                setTimeout(updateTime, 1000);
            } catch (error) {
                console.error('时间更新错误:', error);
            }
        }

        // 全屏功能
        function toggleFullscreen() {
            try {
                if (!document.fullscreenElement) {
                    document.documentElement.requestFullscreen();
                } else {
                    document.exitFullscreen();
                }
            } catch (error) {
                alert('全屏切换失败: ' + error.message);
            }
        }

        // 主题切换
        function changeTheme(theme) {
            const body = document.body;
            switch(theme) {
                case 'blue':
                    body.style.backgroundColor = '#0000ff';
                    body.style.color = '#fff';
                    break;
                case 'black':
                    body.style.backgroundColor = '#000';
                    body.style.color = '#fff';
                    break;
                case 'white':
                    body.style.backgroundColor = '#fff';
                    body.style.color = '#000';
                    break;
            }
        }

        // 初始化
        document.addEventListener('DOMContentLoaded', () => {
            updateTime(); // 确保立即执行
            document.getElementById('clock').style.visibility = 'visible';
        });
    </script>
</body>
</html>